import {emit} from "@tauri-apps/api/event";
import {useUserStore} from "../stores/user.ts";
import {storeToRefs} from "pinia";
import {useUserMessageStore} from "../stores/user_message.ts";
import {messageMapSave} from "./message_map_save.ts";

export async function sendTextMessage(content: string) {
    let {userInfo,toUserAccount} = storeToRefs(useUserStore());
    let msg = {
        sender_account: userInfo.value.account,
        to_account: toUserAccount.value,
        message_type: "Text",
        content: content,
    };
    messageMapSave(msg,true);
    await emit("send-message", msg).then(() => {
        console.log("send-message-text successfully");
    });
}